import requests
import json

def chat_gpt_azure(prompt):
    # 客户提供的 API Key 和 URL
    api_key = '18OsYf3KYkcS5Eb78j1U3cPgl4OW6Q6nWfdIaRPk4USYx7orwLgEJQQJ99BCACHYHv6XJ3w3AAABACOGWaXL'
    url = "https://gai-oai.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2025-01-01-preview"

    # 请求头
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    # 请求体
    data = {
        "model": "Gpt-4o",
        "messages": [
            {"role": "system", "content": "You are a helpful assistant."},
            {"role": "user", "content": prompt}
        ]
    }

    # 发送 POST 请求
    response = requests.post(url, headers=headers, data=json.dumps(data))

    # 处理响应
    if response.status_code == 200:

        print("Response:", response.json()['choices'][0]['message']['content'])
    else:
        print("Error:", response.status_code, response.text)
    return response.json()['choices'][0]['message']['content']

def chat_gpt_azure_msg(msg):
    # 客户提供的 API Key 和 URL
    api_key = '18OsYf3KYkcS5Eb78j1U3cPgl4OW6Q6nWfdIaRPk4USYx7orwLgEJQQJ99BCACHYHv6XJ3w3AAABACOGWaXL'
    url = "https://gai-oai.openai.azure.com/openai/deployments/gpt-4o/chat/completions?api-version=2025-01-01-preview"

    # 请求头
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }

    # 请求体
    data = {
        "model": "Gpt-4o",
        "messages": msg
    }

    # 发送 POST 请求
    response = requests.post(url, headers=headers, data=json.dumps(data))

    # 处理响应
    if response.status_code == 200:

        print("Response:", response.json()['choices'][0]['message']['content'])
    else:
        print("Error:", response.status_code, response.text)
    return response.json()['choices'][0]['message']['content']